package com.wang.mandkey.views;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;

public class WheelView extends View {

	private String tag = WheelView.this.getClass().getSimpleName();
	private MouseWheelListener mMouseWheelListener;

	public MouseWheelListener getmMouseWheelListener() {
		return mMouseWheelListener;
	}

	public void setmMouseWheelListener(MouseWheelListener mMouseWheelListener) {
		this.mMouseWheelListener = mMouseWheelListener;
	}

	public WheelView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public WheelView(Context context) {
		super(context);
	}

	float lasxtY = 0;

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		int action = event.getAction();
		float y = event.getY();
		switch (action) {
		case MotionEvent.ACTION_DOWN: {
			lasxtY = y;
		}
			break;
		case MotionEvent.ACTION_MOVE: {
			if (null != mMouseWheelListener) {
				int detalY = (int) (lasxtY - y);
				if (detalY != 0) {
					mMouseWheelListener.OnMouseWheelChange(detalY);
					Log.i(tag, "deltaY:"+detalY);
				}
			}
			lasxtY = y;
		}
			break;
		default:
			break;
		}

		return true;
	}

	public static interface MouseWheelListener {
		public void OnMouseWheelChange(int change);

	}
}
